package com.aduerr.v1shouyin.mvp.base;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.annotation.LayoutRes;
import butterknife.ButterKnife;
import com.aduerr.v1shouyin.App;
import com.aduerr.v1shouyin.mvp.interfaces.NetChangeObserver;
import com.aduerr.v1shouyin.util.NetUtils;
import com.hannesdorfmann.mosby3.mvp.MvpActivity;
import com.hannesdorfmann.mosby3.mvp.MvpPresenter;
import com.hannesdorfmann.mosby3.mvp.MvpView;

/**
 * @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
 * @since 2017/2/20
 */

public abstract class BaseActivity<V extends MvpView, P extends MvpPresenter<V>> extends MvpActivity<V, P> {
    protected Context context;
    /**
     * 网络观察者
     */
    protected NetChangeObserver mNetChangeObserver = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(getRootViewId());
//        initUI();

        //禁止横竖屏切换
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        context = this;
//        initSystemBar();//http://mp.weixin.qq.com/s/SOc45NalA0NErr2UtNfuIA
        // 网络改变的一个回掉类
        mNetChangeObserver = new NetChangeObserver() {
            @Override
            public void onNetConnected(NetUtils.NetType type) {

                onNetworkConnected(type);
            }

            @Override
            public void onNetDisConnect() {

                onNetworkDisConnected();
            }
        };

        //开启广播去监听 网络 改变事件
//        NetStateReceiver.registerObserver(mNetChangeObserver);

    }

    protected abstract void onNetworkDisConnected();

    protected abstract void onNetworkConnected(NetUtils.NetType type);

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);
        ButterKnife.bind(this);
    }


//    public <T> void  toSetList(List<T> list, List<T> newList, boolean isMore){
//
//        if(list!=null && newList!=null){
//            synchronized (BaseFragment.class){
//                if(!isMore){
//                    list.clear();
//                }
//                list.addAll(newList);
//            }
//        }
//    }


    public App getApp() {
        return (App) getApplication();
    }


//    public abstract int getRootViewId();

    public abstract void initUI();

    public abstract void initData();

}
